package vn.com.epi.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class ClientTest {

    public static void main(String[] args) {
        try {
            URL url = new URL("http://10.198.44.64:8080/LoggingServices/rest/log");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "text/plain");
//            String input = "1381755554,FA92845A-C9BE-4A40-A22D-0000E93061A1,VAL1,12168155,87\n" + 
//                    "1381782679,FA92845A-C9BE-4A40-A22D-0000E93061A1,VAL1,12170984,141\n" +
//                    "1381782260,FA92845A-C9BE-4A40-A22D-0000E93061A1,VAL1,12171171,87\n" +
//                    "1381782378,FA92845A-C9BE-4A40-A22D-0000E93061A1,VAL1,12171185,87\n" +
//                    "1381781658,FA92845A-C9BE-4A40-A22D-0000E93061A1,VAL1,12171282,87\n" +
//                    "1381749730,D882971B-48D0-4C36-BB34-00010715A190,VAL1,12161432,122\n" +
//                    "1381749730,D882971B-48D0-4C36-BB34-00010715A190,VAL2,12161981,122\n" +
//                    "1381661272,69052F75-3420-4196-A934-000159F3E89B,VAL1,12160042,104";
//            String input = "xin chào";
            String input = "";
            OutputStream os = conn.getOutputStream();
            os.write(input.getBytes());
            os.flush();
            if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
                throw new RuntimeException("Failed : HTTP error code : "
                        + conn.getResponseCode());
            }
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    (conn.getInputStream())));
            String output;
            System.out.println("Output from Server .... \n");
            while ((output = br.readLine()) != null) {

                System.out.println(output);
            }
            conn.disconnect();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
